package com.medicine.web.controller.manage.block;

import com.medicine.common.annotation.Log;
import com.medicine.common.core.controller.BaseController;
import com.medicine.common.core.domain.AjaxResult;
import com.medicine.common.core.domain.entity.SysDept;
import com.medicine.common.core.page.TableDataInfo;
import com.medicine.common.enums.BusinessType;
import com.medicine.common.utils.poi.ExcelUtil;
import com.medicine.manage.block.WeBASESignUtil;
import com.medicine.manage.block.domain.UserExtend;

import com.medicine.manage.block.entity.WeBaseSignResult;
import com.medicine.manage.block.service.IUserExtendService;
import com.medicine.manage.block.service.TestService;
import com.medicine.manage.domain.Boiling;
import com.medicine.manage.domain.Order;
import com.medicine.manage.domain.OrderProcess;
import com.medicine.manage.service.IBoilingService;
import com.medicine.manage.service.block.IBlockService;
import com.medicine.system.service.ISysDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 煎药Controller
 * 
 * @author admin
 * @date 2024-10-14
 */
@RestController
@RequestMapping("/manage/block")
public class BlockController extends BaseController
{

    @Value("${ruoyi.name}")
    private String name;

    @Autowired
    private WeBASESignUtil weBASESignUtil;


    @Autowired
    private IBlockService blockService;

    @Autowired
    private TestService testService;

    @Autowired
    private IUserExtendService userExtendService;

    @Autowired
    private ISysDeptService deptService;

    /**
     * 查询煎药列表
     */

    @GetMapping("/createUser")
    public UserExtend createUser(String userName)
    {
        UserExtend signUser = weBASESignUtil.createSignUser(userName);

        return signUser;
    }



    @Log(title = "煎药", businessType = BusinessType.INSERT)
    @PostMapping("/deploy")
    public AjaxResult add(@RequestBody SysDept dept)
    {

        UserExtend userExtend =userExtendService.getAdminUserByDeptId(dept.getDeptId());
        String contractAddressStr = blockService.deployContract(userExtend.getSignUserId());
        dept.setContractAddress(contractAddressStr);
        dept.setContractName(this.name + "-" + dept.getDeptName());
        return toAjax(deptService.updateDept(dept));
    }





//    /**
//     * 导出煎药列表
//     */
//    @PreAuthorize("@ss.hasPermi('manage:boiling:export')")
//    @Log(title = "煎药", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Boiling boiling)
//    {
//        List<Boiling> list = boilingService.selectBoilingList(boiling);
//        ExcelUtil<Boiling> util = new ExcelUtil<Boiling>(Boiling.class);
//        util.exportExcel(response, list, "煎药数据");
//    }
//
//    /**
//     * 获取煎药详细信息
//     */
//    @PreAuthorize("@ss.hasPermi('manage:boiling:query')")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return success(boilingService.selectBoilingById(id));
//    }
//
//    /**
//     * 新增煎药
//     */
//    @PreAuthorize("@ss.hasPermi('manage:boiling:add')")
//    @Log(title = "煎药", businessType = BusinessType.INSERT)
//    @PostMapping
//    public AjaxResult add(@RequestBody Boiling boiling)
//    {
//        return toAjax(boilingService.insertBoiling(boiling));
//    }
//
//    /**
//     * 修改煎药
//     */
//    @PreAuthorize("@ss.hasPermi('manage:boiling:edit')")
//    @Log(title = "煎药", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody Boiling boiling)
//    {
//        return toAjax(boilingService.updateBoiling(boiling));
//    }
//
//    /**
//     * 删除煎药
//     */
//    @PreAuthorize("@ss.hasPermi('manage:boiling:remove')")
//    @Log(title = "煎药", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(boilingService.deleteBoilingByIds(ids));
//    }
}
